<template>
  <f7-page>
    <f7-navbar title="添加车辆" back-link="返回"></f7-navbar>

    <f7-list>
      <f7-list-item smart-select title="选择分组">
        <select name="fruits" v-model="newCar.group_id">
          <option :value="item._id" v-for="item in driverGroup">{{item.name}}</option>
        </select>
      </f7-list-item>
      <f7-list-item class="add_list">
        <label>车牌号</label>
        <input type='text' v-model='newCar.number'/>
      </f7-list-item>
      <f7-list-item class="add_list">
        <label>手机号</label>
        <input type="number" v-model.number="newCar.phone" placeholder="请输入手机号" />
      </f7-list-item>
      <f7-list-item class="add_list">
        <label>姓名</label>
        <input type="text" v-model="newCar.real_name" placeholder="请输入姓名"/>
      </f7-list-item>
      <f7-list-item class="add_list">
        <label>载重量</label>
        <input type="number" v-model.number="newCar.weight" placeholder="请输入载重量"/>
      </f7-list-item>
      <f7-list-item title="运输种类">
        <div>
          <span v-for="item in productTodo">
            <input type="checkbox" :value="item.eng" v-model="newCar.transport">
            <label>{{item.chn}}</label>
          </span>
        </div>
      </f7-list-item>

      <div class="btn">
        <div class="title" @click="submit">确认添加</div>
      </div>
    </f7-list>
    <div>
      {{newCar}}
    </div>
  </f7-page>
</template>

<script>
    import F7Button from "framework7-vue/src/components/button";
    export default {
        name: 'addDriver',
        data: function () {
            return {
                seleCar: '',
                passtoto:[],
                newCar:{
                    group_id:'',
                    number:'',
                    phone:'',
                    weight:'',
                    transport:[],
                    real_name:''
                },
                productTodo:'',
                driverGroup: ''
            }
        },
        components: {
            F7Button
        },
        methods: {
            async getProductClassify () {
                let param = {type: 'registered'}
                this.productTodo = (await this.ProductService.getProductType(param)).data.data
            },
            async getListGroup(){
                let param = {type: "DRIVER"}
                this.driverGroup=(await this.AccountService.getCarGroup(param)).data.data
            },
            async submit(){
                let flag=true;

                //交验数据
                if(!this.newCar.number || !this.newCar.phone || !this.newCar.weight || this.newCar.transport.length==0 || !this.newCar.real_name){
                    flag=false;
                    alert('请填写完整信息')
                }
                if(flag){

                    this.submit=(await this.AccountService.addCarDtl(this.newCar)).data;
                    if(this.submit.status=='err'){
                        alert(this.submit.msg)
                    }else if(this.submit.status=='success'){
                        alert('添加成功')
                    }else{
                        alert('其他故障')
                    }
                }

            }
        },
        mounted () {
            this.getProductClassify()
            this.getListGroup()
        }
    }
</script>

<style scoped>
  label{
    font-size: 14px;
    width: 200px;
  }
  .add_list input{
    float: right;
    width: auto;
    text-align: right;
  }
  .btn{
    position: fixed;
    bottom: 0;
    background: #a3a2f0;
    width: 100%;
    line-height: 40px;
    text-align: center;
    color: white;
  }
</style>
